package org.xxforest.game.core.utils;

import org.xxforest.game.core.assets.XXAsnycLoader;
import org.xxforest.game.core.assets.XXAssetManager;

import com.badlogic.gdx.graphics.Texture;

/**
 * 资源工具类
 * EG:
 * ....
 * 添加异步加载
 * addTextureLoader("boo.jpg") 
 * 获取纹理
 * getTexture("boo.jpg")
 * ....
 * @author 刘海明
 *
 */
public class XXAssetUtils {

	private static XXAssetUtils assetUtils ;
	
	private XXAssetManager assetManager ;
	
	private XXAssetUtils(){
		assetManager = XXAssetManager.create() ;
	}
	
	public void addLoader(XXAsnycLoader loader) {
		assetManager.addLoader(loader);
	}

	/**
	 * 添加异步加载纹理
	 * @param fileName
	 */
	public void addTextureLoader(String fileName) {
		assetManager.addTextureLoader(fileName);
	}

	public boolean isLoadFinish() {
		return assetManager.isLoadFinish();
	}
	
	public void disposeAsset(String fileName) {
		assetManager.disposeAsset(fileName);
	}

	public static XXAssetUtils getInstance() {
		if(assetUtils == null){
			assetUtils = new XXAssetUtils() ;
		}
		return assetUtils;
	}
	
	public XXAssetManager getAssetManager() {
		return assetManager;
	}

	/**
	 * 获取纹理
	 * @param fileName
	 * @return
	 */
	public Texture getTexture(String fileName){
		return assetManager.getLoader(fileName).getData() ;
	}
}
